/**
 * Copyright 2010 Butin Kirill <kiryaka@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.flexupload.status
{
	import mx.formatters.NumberFormatter;

	public class MessageHelper
	{
		private var formatter:NumberFormatter = new NumberFormatter();
		public function MessageHelper(){
			formatter.precision = 1;
		}
		public function humanReadableSpeed(bytes:uint):String{
			var ext:Array = new Array("Gbit", "Mbit", "Kbit", "Bit");
			//var ext:Array = new Array("Гбит", "Мбит", "Кбит", "Бит");
			var size:Number = bytes*8;
			var res:String = formatter.format(size) + ext.pop();
			while (size > 1024){
				size = size/1024;
				res = formatter.format(size) + ext.pop();
			}
			return res;
		}
		public function humanReadableSize(bytes:uint):String{
			var ext:Array = new Array("Gb", "Mb", "Kb", "Bytes");
			//var ext:Array = new Array("Гб", "Мб", "Кб", "Байт");
			var size:Number = bytes;
			var res:String = formatter.format(size) + ext.pop();
			while (size > 1024){
				size = size/1024;
				res = formatter.format(size) + ext.pop();
			}
			return res;
		}		
	}
}